<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #ggk{
            width: 600px;
            height: 400px;
            font-size: 30px;
            font-weight: 900;
            text-align: center;
            line-height: 400px;
            overflow: hidden;
            position: absolute;
            left: 0;
            top: 0;
        }

        canvas{
            border: 1px solid #1100cc;
            position: absolute;
            left: 0;
            top:0;
            z-index: 10;
        }

    </style>
</head>
<body>
    <div id='ggk'>谢谢惠顾</div>
    <canvas id='c1' width="600" height="400">
        浏览器不支持canvas
    </canvas>
    <script>
        /** @type {HTMLCanvasElement}**/
        var c1 = document.getElementById('c1')
        if(!c1.getContext){
            console.log('浏览器不支持')
        }
        var ctx = c1.getContext('2d')

        let img = new Image()
        img.src = './img/ggk.jpg';
        img.onload = function(){
            ctx.drawImage(img,0,0,600,400);
        }

        var isDraw = false;
        c1.onmousedown = function(e){
            isDraw = true;
        }

        c1.onmouseup = function(e){
            isDraw = false;
        }

        c1.onmousemove =function(e){
            if(isDraw){
                var x = e.pageX;
                var y = e.pageY;

                ctx.globalCompositeOperation = "destination-out"
                ctx.moveTo(x,y);
                ctx.arc(x,y,20,0,Math.PI*2)
                ctx.fill();
            }
        }

        let random = Math.random();
        if(random<0.1){
            var ggDiv =  document.querySelector('#ggk');
            ggDiv.innerHTML = '恭喜你中大奖';
        }
    </script>
</body>
</html>